package com.hadoop.mr2.mutipleoutput;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.MultipleOutputs;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import com.hadoop.mr2.output.AuthOutputFormat;

public class MultipleDriver {
	
	public static void main(String[] args) throws Exception {
		Configuration conf=new Configuration();
		Job job=Job.getInstance(conf);
		
		job.setJarByClass(MultipleDriver.class);
		job.setMapperClass(MultipleOutputMapper.class);
		job.setReducerClass(MultipleOutputReducer.class);
		
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(Text.class);
		
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(Text.class);
		//利用多输出源，做结果的输出，注意，不是分区。此外需要,标识名要和reduce里的名字一致
		MultipleOutputs.addNamedOutput(job,"jaryfile",TextOutputFormat.class,Text.class,Text.class);
		MultipleOutputs.addNamedOutput(job,"rosefile",TextOutputFormat.class,Text.class,Text.class);
		MultipleOutputs.addNamedOutput(job,"tomfile",AuthOutputFormat.class,Text.class,Text.class);
		
		FileInputFormat.addInputPath(job, new Path("hdfs://192.168.234.231:9000/inputscore"));
		FileOutputFormat.setOutputPath(job, new Path("hdfs://192.168.234.231:9000/inputscore/result"));
		
		job.waitForCompletion(true);
		
	}

}
